package com.rw.coco;

import com.rw.coco.api.bot.CocoApi;
import com.rw.coco.api.bot.handler.GroupKickHandler;
import com.rw.coco.api.bot.handler.GroupMuteHandler;
import com.rw.coco.api.bot.handler.MessageHandler;
import com.rw.coco.api.data.CocoDataApi;
import com.rw.coco.api.data.ConfigMapper;
import com.rw.coco.api.log.CocoLogger;
import com.rw.coco.api.reply.CocoReplyApi;
import com.rw.coco.handler.CocoGroupKickHandler;
import com.rw.coco.handler.CocoGroupMuteHandler;
import com.rw.coco.handler.CocoMessageHandler;
import com.rw.coco.handler.message.reply.util.FrequencyLimit;
import com.rw.coco.util.CocoData;
import com.rw.coco.util.DefaultConfigMapper;
import com.rw.coco.util.config.CocoConfig;
import lombok.Getter;

/**
 * 可可对象
 */
@Getter
public class Coco implements CocoApi {
    private final CocoGroupKickHandler cocoGroupKickHandler;

    private final CocoGroupMuteHandler cocoGroupMuteHandler;

    private final CocoMessageHandler cocoMessageHandler;

    public Coco(CocoDataApi dataApi, CocoReplyApi replyApi, CocoLogger cocologger) {
        this(dataApi, replyApi, cocologger, new DefaultConfigMapper());
    }

    public Coco(CocoDataApi dataApi, CocoReplyApi replyApi, CocoLogger cocologger, ConfigMapper configMapper) {
        CocoConfig cocoConfig = new CocoConfig(configMapper);
        FrequencyLimit frequencyLimit = new FrequencyLimit(cocoConfig, dataApi.getCacheMapper());
        CocoData cocoData = new CocoData(cocoConfig, frequencyLimit);
        this.cocoGroupKickHandler = new CocoGroupKickHandler(dataApi, cocologger, cocoData);
        this.cocoGroupMuteHandler = new CocoGroupMuteHandler(dataApi, cocologger, cocoData);
        this.cocoMessageHandler = new CocoMessageHandler(dataApi, replyApi, cocologger, cocoData);
    }

    @Override
    public GroupKickHandler getGroupKickHandler() {
        return cocoGroupKickHandler;
    }

    @Override
    public GroupMuteHandler getGroupMuteHandler() {
        return cocoGroupMuteHandler;
    }

    @Override
    public MessageHandler getMessageHandler() {
        return cocoMessageHandler;
    }
}
